package com.wedimob.slideshare.task.io.network;

import java.io.IOException;
import java.net.URL;

import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.wedimob.slideshare.Reader;

public class DefaultReader implements Reader {
    @Override
    public Document get(URL url, int timeout) {
        try {
            return Jsoup.connect(url.toString()).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
            	      .referrer("http://www.google.com").timeout(timeout * 1000).get();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    @Override
    public Response getRaw(URL url, int timeout) {
        try {
            return Jsoup.connect(url.toString()).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
            	      .referrer("http://www.google.com").timeout(timeout * 1000).ignoreContentType(true).execute();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
